package 类和对象课堂练习.异常;
//2：计算平均课时:输入总课时和课程数,计算平均课时.要求捕捉输入和除法错误;如果总课时少于100,抛出课时太少的错误

import java.util.InputMismatchException;
import java.util.Scanner;

public class Zuoye04061 {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        for (; ; ) {
            System.out.println("请输入总课时和课程数：");
            try {
                int a = scan.nextInt();
                int b = scan.nextInt();
                int c = a / b;
                if (a < 100) {
                    System.out.println("输入错误课时太少");
                } else if (b > 0) {
                    System.out.println("平均课时为每节课" + (double) (a) / (double) (b) + "小时");
                    return;
                }
            } catch (ArithmeticException e) {
                System.out.println("课程数不能为0");
            } catch (Exception e) {
                System.out.println("请输入数字：");
                scan.next();
                continue;
            }
        }
    }
}
